import uni from '@dcloudio/vite-plugin-uni'
import Components from '@uni-helper/vite-plugin-uni-components'
import path from 'node:path'
import { NutResolver } from 'nutui-uniapp'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '~': `${path.resolve(__dirname, 'src')}`,
      '@': `${path.resolve(__dirname, 'src')}`,
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "nutui-uniapp/styles/variables.scss";@import "@/styles/nut.scss";',
      },
    },
  },
  plugins: [Components({
    resolvers: [NutResolver()]
  }), uni(), UnoCSS(), AutoImport({
    imports: [
      'vue',
      {
        '[package-name]': [
          '[import-names]',
          // alias
          ['[from]', '[alias]'],
        ],
        "nutui-uniapp/composables": [
          // 在这里添加需要自动导入的API
          "useToast"
        ]
      }
    ],
    include: [
      /\.[tj]sx?$/,
      /\.vue$/,
      /\.vue\?vue/
    ],
    dts: './src/auto-imports.d.ts',
    vueTemplate: true,
    eslintrc: {
      enabled: true,
    },
  })],
  // 发布时删除 console
  build: {
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,
      },
    },
  },
})
